<template>
  <view class="order-confirm-page">
    <cu-custom bgColor="bg-gradual-fff" isBack="true">
      <block slot="content">确认订单</block>
    </cu-custom>
    
    <view class="container">
      <!-- 订单状态卡片 -->
      <view class="status-card" :class="orderdetail.status">
        <view class="status-icon">
          <u-icon v-if="orderdetail.status === 'pending'" name="clock" size="28" color="#FFB800"></u-icon>
          <u-icon v-else-if="orderdetail.status === 'completed'" name="checkmark-circle" size="28" color="#19BE6B"></u-icon>
          <u-icon v-else name="close-circle" size="28" color="#FA3534"></u-icon>
        </view>
        <view class="status-text">
          <text v-if="orderdetail.status === 'pending'">待处理</text>
          <text v-else-if="orderdetail.status === 'completed'">已完成</text>
          <text v-else>已取消</text>
        </view>
        <view class="order-id">订单号: {{orderdetail.id}}</view>
      </view>
      
      <!-- 商品信息 -->
      <view class="section goods-info">
        <view class="section-title">商品信息</view>
        <view class="goods-item">
          <view class="goods-basic">
            <text class="goods-id">商品ID: {{orderdetail.goodsId}}</text>
            <text class="goods-price">{{orderdetail.totalAmount.toFixed(2)}}积分</text>
          </view>
          <view class="discount" v-if="orderdetail.discount > 0">
            优惠: -¥{{orderdetail.discount.toFixed(2)}}
          </view>
        </view>
      </view>
      
      <!-- 联系人信息 -->
      <view class="section contact-info">
        <view class="section-title">联系人信息</view>
        <view class="info-item">
          <text class="info-label">姓名:</text>
          <text class="info-value">{{orderdetail.contactName}}</text>
        </view>
        <view class="info-item">
          <text class="info-label">电话:</text>
          <text class="info-value">{{orderdetail.contactPhone}}</text>
        </view>
      </view>
      
      <!-- 预约信息 -->
      <view class="section booking-info" v-if="orderdetail.bookingDate || orderdetail.bookingTime">
        <view class="section-title">预约信息</view>
        <view class="info-item" v-if="orderdetail.bookingDate">
          <text class="info-label">预约日期:</text>
          <text class="info-value">{{orderdetail.bookingDate}}</text>
        </view>
        <view class="info-item" v-if="orderdetail.bookingTime">
          <text class="info-label">预约时间:</text>
          <text class="info-value">{{orderdetail.bookingTime}}</text>
        </view>
      </view>
      
      <!-- 订单时间 -->
      <view class="section time-info">
        <view class="section-title">订单时间</view>
        <view class="info-item" v-if="orderdetail.createTime">
          <text class="info-label">创建时间:</text>
          <text class="info-value">{{orderdetail.createTime}}</text>
        </view>
        <view class="info-item" v-if="orderdetail.updateTime">
          <text class="info-label">更新时间:</text>
          <text class="info-value">{{orderdetail.updateTime}}</text>
        </view>
        <view class="info-item" v-if="orderdetail.cancelTime">
          <text class="info-label">取消时间:</text>
          <text class="info-value">{{orderdetail.cancelTime}}</text>
        </view>
      </view>
      <view class="action-bar" v-if="orderdetail.status === 'pending'">
        <button class="cancel-btn" @click="cancelOrder">取消订单</button>
      </view>
    </view>
  </view>
</template>

<script>
import api from '../../common/apiService';
import request from '../../common/request';
export default {
  data() {
    return {
      id: '',
      orderdetail: {
        address: null,
        bookingDate: null,
        bookingTime: null,
        cancelTime: null,
        contactName: "",
        contactPhone: "",
        couponId: null,
        createBy: null,
        createTime: null,
        discount: 0,
        goodsId: 0,
        hasReviewed: false,
        id: "",
        requirements: null,
        status: "pending",
        totalAmount: 0,
        updateBy: null,
        updateTime: null,
        userId: 0
      }
    }
  },
  onLoad: function(options) {
    this.id = options.id;
    this.getorderlist();
  },
  methods: {
    getorderlist() {
      let optsList = {
        url: `api/booking/${this.id}`,
        method: 'get'
      };
      let _this = this;
      request.httpRequest(optsList).then(res => {
        if (res.data.code == 200) {
          _this.orderdetail = res.data.data;
        }
      });
    },
    cancelOrder() {
      uni.showModal({
        title: '确认取消',
        content: '确定要取消此订单吗？',
        success: (res) => {
          if (res.confirm) {
            uni.showLoading({ title: '处理中...' });
			
			
			let optsList = {
			  url: `api/booking/cancel/` + this.id,
			  method: 'put'
			};
			
			request.httpRequest(optsList).then(res => {
			  if (res.data.code == 200) {
				console.log("取消",res.data.data)
			  }
			})
			
			
            setTimeout(() => {
              uni.hideLoading();
              uni.showToast({ title: '订单已取消' });
			  uni.navigateBack()
			  
            }, 1000);
          }
        }
      });
    },
  }
}
</script>

<style lang="scss">
.order-confirm-page {
  background-color: #f7f7f7;
  min-height: 100vh;
  padding-bottom: 120rpx;
  
  .container {
    padding: 20rpx;
  }
  
  .status-card {
    background: #fff;
    border-radius: 16rpx;
    padding: 30rpx;
    margin-bottom: 20rpx;
    display: flex;
    align-items: center;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
    
    &.pending {
      border-left: 8rpx solid #FFB800;
    }
    
    &.completed {
      border-left: 8rpx solid #19BE6B;
    }
    
    &.cancelled {
      border-left: 8rpx solid #FA3534;
    }
    
    .status-icon {
      margin-right: 20rpx;
    }
    
    .status-text {
      font-size: 32rpx;
      font-weight: bold;
      flex: 1;
    }
    
    .order-id {
      font-size: 24rpx;
      color: #999;
    }
  }
  
  .section {
    background: #fff;
    border-radius: 16rpx;
    padding: 30rpx;
    margin-bottom: 20rpx;
    box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
    
    .section-title {
      font-size: 28rpx;
      font-weight: bold;
      margin-bottom: 20rpx;
      color: #333;
      border-bottom: 1rpx solid #eee;
      padding-bottom: 15rpx;
    }
  }
  
  .goods-info {
    .goods-item {
      .goods-basic {
        display: flex;
        justify-content: space-between;
        margin-bottom: 15rpx;
        
        .goods-id {
          color: #666;
        }
        
        .goods-price {
          font-weight: bold;
          color: #FF4D4F;
          font-size: 32rpx;
        }
      }
      
      .discount {
        color: #19BE6B;
        font-size: 26rpx;
      }
    }
  }
  
  .info-item {
    display: flex;
    margin-bottom: 15rpx;
    font-size: 28rpx;
    
    &:last-child {
      margin-bottom: 0;
    }
    
    .info-label {
      color: #666;
      width: 160rpx;
    }
    
    .info-value {
      color: #333;
      flex: 1;
    }
  }
  
  .action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100rpx;
	margin: 0 auto;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30rpx;
    box-shadow: 0 -4rpx 12rpx rgba(0, 0, 0, 0.05);
    
    button {
      height: 80rpx;
      line-height: 80rpx;
      border-radius: 40rpx;
      font-size: 28rpx;
      margin: 0 auto;
      flex: 0.48;
      
      &.cancel-btn {
        background: #fff;
        color: #666;
        border: 1rpx solid #ddd;
      }
    }
  }
}
</style>